<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/10
 * Time: 23:51
 */
include '../classes/logincheck.php';
include '../classes/conn.php';
if(islogin()=='teacher_login'){
    if($_POST['type']=='sec'){
        $query1="select taken from section  where num={$_POST['sec_num']} and class='{$_POST['class_num']}' and teacher='{$_SESSION['t_num']}'";

        $taken=mysql_fetch_row(mysql_query($query1));
        if($taken[0]==1){
            $taken[0]=0;
        }
        else if($taken[0]==0){
            $taken[0]='1';
        }
        $query="update section set taken='{$taken[0]}' 
where num={$_POST['sec_num']} and class='{$_POST['class_num']}' and teacher='{$_SESSION['t_num']}'";
        $res=mysql_query($query);
        if($res){
            echo '1';
        }
        else echo '0';
    }
    else if($_POST['type']='sub'){

        $query1="select taken from subsection  where
 num={$_POST['sub_num']} and class='{$_POST['class_num']}' and teacher='{$_SESSION['t_num']}'and section ='{$_POST['sec_num']}'";
        $taken=mysql_fetch_row(mysql_query($query1));
        if($taken[0]=='1'){
            $taken[0]=0;
        }
        else if($taken[0]=='0'){
            $taken[0]='1';
        }
        $query="update subsection set taken='{$taken[0]}' 
where num={$_POST['sub_num']} and class='{$_POST['class_num']}' and teacher='{$_SESSION['t_num']}' and section ='{$_POST['sec_num']}'";
        $res=mysql_query($query);
        if($res){
            echo '1';
        }
        else echo '0';
    }
    else echo '0';

}
else echo '0';